package org.lql.algo.codecrush.week005;

import org.lql.algo.common.ListNode;

/**
 * @author: liangqinglong
 * @date: 2025-08-05 17:53
 * @description: LCR 141. 训练计划 III <a href="https://leetcode.cn/problems/fan-zhuan-lian-biao-lcof/description/">...</a>
 **/
public class TrainningPlan {

	/**
	 * 给定一个头节点为 head 的单链表用于记录一系列核心肌群训练编号，请将该系列训练编号 倒序 记录于链表并返回。
	 * <p>
	 * <p>
	 * <p>
	 * 示例 1：
	 * <p>
	 * 输入：head = [1,2,3,4,5]
	 * 输出：[5,4,3,2,1]
	 * <p>
	 * <p>
	 * 示例 2：
	 * <p>
	 * 输入：head = [1,2]
	 * 输出：[2,1]
	 * <p>
	 * <p>
	 * 示例 3：
	 * <p>
	 * 输入：head = []
	 * 输出：[]
	 * <p>
	 * <p>
	 * 提示：
	 * <p>
	 * 链表中节点的数目范围是 [0, 5000]
	 * -5000 <= Node.val <= 5000
	 */
	public ListNode trainningPlan(ListNode head) {
		ListNode last = null;
		while (head != null) {
			ListNode next = head.next;
			head.next = last;
			last = head;
			head = next;
		}
		return last;
	}


	public static void main(String[] args) {
		TrainningPlan trainningPlan = new TrainningPlan();
		ListNode head = new ListNode(1);
		head.next = new ListNode(2);
		head.next.next = new ListNode(3);
		head.next.next.next = new ListNode(4);
		head.next.next.next.next = new ListNode(5);
		ListNode listNode = trainningPlan.trainningPlan(head);
		ListNode.printList(listNode);
	}
}
